package com.phpxiu.app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;

/**
 * Created by 吴金洲 on 2016/9/7
 */
public class UpdateDialog extends Dialog implements View.OnClickListener{
    private TextView descView;
    private String versionCode;//提示更新的版本号
    private OnUpdateCallBack mCallBack;

    public UpdateDialog(Context context) {
        super(context, R.style.interactiveDialog);
        init(context);
    }

    private void init(Context context){
        setContentView(R.layout.update_dialog);
        descView=(TextView)findViewById(R.id.version_description);
        findViewById(R.id.base_view).setOnClickListener(this);
        findViewById(R.id.update).setOnClickListener(this);
        findViewById(R.id.cancel).setOnClickListener(this);
    }

    public void setCallBack(OnUpdateCallBack mCallBack) {
        this.mCallBack = mCallBack;
    }

    public void show(String versionCode,String msg){
        this.versionCode=versionCode;
        if(msg!=null){
            descView.setText(msg);
        }
        super.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.base_view:

                break;
            case R.id.cancel:
                if(mCallBack!=null){
                    mCallBack.onAppUpdate(true,versionCode);
                }
                break;
            case R.id.update:
                if(mCallBack!=null){
                    mCallBack.onAppUpdate(false,versionCode);
                }
                break;
        }
        dismiss();
    }



    public interface OnUpdateCallBack{
        void onAppUpdate(boolean isIgnore, String version);
    }

}
